﻿#region 信息

// Copyright©2014 Rex Rao all rights reserved.
// File name : SoMcCoffee\Sohobloo.SoCommon\Appender.cs
// Author : Sohobloo
// Create time : 2014/02/02 1:30
// Update time : 2014/02/05 8:55

#endregion

#region 引用

using System;
using System.IO;
using System.Text;
using log4net.Appender;
using log4net.Core;
using log4net.Filter;
using log4net.Layout;

#endregion

namespace Sohobloo.SoCommon.Log
{
    internal sealed class Appender : RollingFileAppender
    {
        private static readonly PatternLayout DefaultLayout = new PatternLayout
        {
            ConversionPattern = "%m",
        };

        public Appender(Level level, string name = null)
        {
            DatePattern = "yyyyMMdd\".log\"";
            Encoding = Encoding.Unicode;
            AppendToFile = true;
            LockingModel = new MinimalLock();
            ImmediateFlush = true;
            RollingStyle = RollingMode.Date;
            StaticLogFileName = false;
            Name = string.Format("{0}Appender", name ?? level.ToString());
            File = Path.Combine(Environment.CurrentDirectory, @"Log", (name ?? level.ToString()) + @"\");
            Layout = DefaultLayout;
            Threshold = level;
            AddFilter(new LevelRangeFilter
            {
                LevelMin = level,
                LevelMax = level
            });

            ActivateOptions();
        }
    }
}